package com.maxatime.service.impl;

import com.maxatime.dao.DormitoryMapper;
import com.maxatime.dao.StudentDormitoryRelationMapper;
import com.maxatime.exception.PhoenixException;
import com.maxatime.pojo.*;
import com.maxatime.service.DormitoryService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author Mr.Zhao
 * @title: DormitoryServiceImpl
 * @projectName phoenix
 * @description: TODO
 * @date 2021/8/12 19:43
 */
@Service
public class DormitoryServiceImpl implements DormitoryService {
     Logger log= LogManager.getLogger();
  @Autowired
   private DormitoryMapper dormitoryMapper;
  @Autowired
  private StudentDormitoryRelationMapper studentDormitoryRelationMapper;

    @Override
    public List<Dormitory> dormitoryFind(DormitoryVo vo) {


        return dormitoryMapper.dormitoryFind(vo);
    }

    @Override
    public Integer dormitoryDelete(int pkId) {
        return dormitoryMapper.dormitoryDelete(pkId);
    }

    @Override
    public Integer updatedor(Dormitory dormitory) throws PhoenixException {
        try {
            return dormitoryMapper.updateByPrimaryKeySelective(dormitory);
        }catch (Exception e){
             log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+dormitory);
            log.error("dormitoryMapper.updateByPrimaryKeySelective:::"+e.getMessage());

            throw new PhoenixException("9999","修改失败");
        }

    }

    @Override
    public Integer insertdor(Dormitory dormitory) throws PhoenixException {
        try {
            return dormitoryMapper.insertSelective(dormitory);
        }catch (Exception e){
            log.error("dormitoryMapper.insertSelective:::"+dormitory);
            log.error("dormitoryMapper.insertSelective:::"+e.getMessage());
            throw new PhoenixException("9999","添加失败");
        }


    }

    @Override
    public Integer deleteListDor(List<Integer> list) {
        return dormitoryMapper.deleteListDor(list);
    }

    @Override
    public Dormitory selectKeydor(Integer id) {
        return dormitoryMapper.selectByPrimaryKey(id);
    }

    @Override
    public StudentDormitoryRelation selectKeys(String studentId) {
        return studentDormitoryRelationMapper.selectKeys(studentId);
    }

    @Override
    public List<StudentDormitoryRelation> select(String dormitoryDormitoryId) {
        return studentDormitoryRelationMapper.select(dormitoryDormitoryId);
    }

    @Override
    public Integer insert(StudentDormitoryRelation dorm) {
        return studentDormitoryRelationMapper.insertSelective(dorm);
    }

    @Override
    public List<StudentMessage> viewdormitorys(String dormitoryId) {
        return dormitoryMapper.viewdormitorys(dormitoryId);
    }

    @Override
    public Integer dorStuDelete(int studentId) {
        return studentDormitoryRelationMapper.dorStuDelete(studentId);
    }

    @Override
    public Integer updatedoruser(String dormitoryDormitoryId) {
        return dormitoryMapper.updatedoruser(dormitoryDormitoryId);
    }

    @Override
    public Integer selectnownum(String dormitoryId) {
        return dormitoryMapper.selectnownum(dormitoryId);
    }

    @Override
    public Integer dorNa(String dormitoryId) {
        return studentDormitoryRelationMapper.dorNa(dormitoryId);
    }

    @Override
    public Integer updatedoUser(String dormitoryId) {
        return dormitoryMapper.updatedoUser(dormitoryId);
    }


}
